package weather.language;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Set;
import java.util.TreeMap;

import org.junit.Test;

import weather.language.exceptions.DateNotFoundException;
import weather.language.exceptions.PlaceNotFoundException;

public class ForecastEngineTest {

	@Test
	public void testPrepareDateToSiteMap1() throws PlaceNotFoundException, DateNotFoundException 
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be $(wkey_1) in $(site_1) on $(date_1) and $(date_2) in $(site_2)?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(2,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		assertTrue(dateToSite.containsKey("$(date_2)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(1,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
		
		TreeMap<String, ArrayList<String>> date_2 = dateToSite.get("$(date_2)");
		assertEquals(1,date_2.size());
		assertTrue(date_2.containsKey("$(site_2)"));
		ArrayList<String> word2 = date_2.get("$(site_2)");
		assertEquals(1,word2.size());
		assertEquals("$(wkey_1)", word2.get(0));
		
	}
	@Test
	public void testPrepareDateToSiteMap2() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be $(wkey_1) in $(site_1) on $(date_1) and  $(date_2) $(wkey_2) in $(site_2)?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(2,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		assertTrue(dateToSite.containsKey("$(date_2)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(1,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
		
		TreeMap<String, ArrayList<String>> date_2 = dateToSite.get("$(date_2)");
		assertEquals(1,date_2.size());
		assertTrue(date_2.containsKey("$(site_2)"));
		ArrayList<String> word2 = date_2.get("$(site_2)");
		assertEquals(1,word2.size());
		assertEquals("$(wkey_2)", word2.get(0));
		
	}
	@Test
	public void testPrepareDateToSiteMap3() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be $(wkey_1) in $(site_1) and $(site_2) and  $(wkey_2) in $(site_3) on $(date_1)?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(1,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(3,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		assertTrue(date_1.containsKey("$(site_2)"));
		assertTrue(date_1.containsKey("$(site_3)"));
		
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
		ArrayList<String> word2 = date_1.get("$(site_2)");
		assertEquals(1,word2.size());
		assertEquals("$(wkey_1)", word2.get(0));
		
		ArrayList<String> word3 = date_1.get("$(site_3)");
		assertEquals(1,word3.size());
		assertEquals("$(wkey_2)", word3.get(0));
		
		
		
	}
	@Test
	public void testPrepareDateToSiteMap4() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be $(wkey_1) in $(site_1) and $(date_1) and  $(date_2)?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(2,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		assertTrue(dateToSite.containsKey("$(date_2)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(1,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
		TreeMap<String, ArrayList<String>> date_2 = dateToSite.get("$(date_2)");
		assertEquals(1,date_2.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		
		ArrayList<String> word2 = date_2.get("$(site_1)");
		assertEquals(1,word2.size());
		assertEquals("$(wkey_1)", word1.get(0));
			
		
	}
	@Test
	public void testPrepareDateToSiteMap5() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be $(wkey_1) in $(site_1) on $(date_1)?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(1,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(1,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
			
		
	}
	@Test
	public void testPrepareDateToSiteMap6() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be in $(site_1)  $(wkey_1) on $(date_1)?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(1,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(1,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
			
		
	}
	@Test
	public void testPrepareDateToSiteMap7() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be on $(date_1)  $(wkey_1) in $(site_1)?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(1,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(1,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
			
		
	}
	@Test
	public void testPrepareDateToSiteMap8() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be in $(site_1) on $(date_1) $(wkey_1) ?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(1,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(1,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
			
		
	}
	@Test
	public void testPrepareDateToSiteMap9() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be on $(date_1) in $(site_1)  $(wkey_1) ?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(1,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(1,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
			
		
	}
	@Test
	public void testPrepareDateToSiteMap10() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be $(wkey_1) in $(site_1) on $(date_1) and $(date_2) $(wkey_2) in $(site_2)?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(2,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		assertTrue(dateToSite.containsKey("$(date_2)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(1,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
		
		TreeMap<String, ArrayList<String>> date_2 = dateToSite.get("$(date_2)");
		assertEquals(1,date_2.size());
		assertTrue(date_2.containsKey("$(site_2)"));
		ArrayList<String> word2 = date_2.get("$(site_2)");
		assertEquals(1,word2.size());
		assertEquals("$(wkey_2)", word2.get(0));
		
	}
	@Test
	public void testPrepareDateToSiteMap11() throws PlaceNotFoundException, DateNotFoundException
	{
		ForecastEngine fe = new ForecastEngine();
		String test1 = "Will it be $(wkey_1) $(date_1) in $(site_1) and $(wkey_2) in $(site_2)?";
		
		TreeMap<String, TreeMap<String, ArrayList<String>>>  dateToSite = fe.prepareDateToSiteMap(test1);
		
		Set<String> dates = dateToSite.keySet();
		assertEquals(1,dates.size());
		assertTrue(dateToSite.containsKey("$(date_1)"));
		
		TreeMap<String, ArrayList<String>> date_1 = dateToSite.get("$(date_1)");
		assertEquals(2,date_1.size());
		assertTrue(date_1.containsKey("$(site_1)"));
		assertTrue(date_1.containsKey("$(site_2)"));
		ArrayList<String> word1 = date_1.get("$(site_1)");
		assertEquals(1,word1.size());
		assertEquals("$(wkey_1)", word1.get(0));
		
		
		ArrayList<String> word2 = date_1.get("$(site_2)");
		assertEquals(1,word2.size());
		assertEquals("$(wkey_2)", word2.get(0));
		
	}
}
